<?php
namespace Mp\Service\Tab;

use Closure;
use Illuminate\Contracts\Support\Renderable;
use  Mp\Service\Tab\Page;

class Tab implements Renderable{

	protected $view = 'Mp::tab.tab';

	protected $pages = [];	

	public function addPage(Page $page){
		array_push($this->pages, $page);
	}

	public function page($content){
		if($content instanceof Closure){
			$page = new Page();
			call_user_func($content,$page);
			$this->addPage($page);
		}elseif($content instanceof String){
			$this->addPage(new Page($content));
		}
		return $this;
	}

	public function variables(){
		return [
			'pages' => $this->pages,
		];
	}



	public function render(){

		return view($this->view,$this->variables())->render();
	}

	public function __toString(){
		return $this->render();
	}


}